<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/UtenteManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../classes/TestManager.php';
require_once  '../bean/Domanda.php';

$connection =ConnectionDB::getInstance()->connectToDB();
$codiceTest = $_GET['codiceTest'];
$key = $_GET['key'];

$test = TestDataManager::getInstance()->getTestByCodice($connection, $codiceTest);
$elencoStudenti = TestDataManager::getInstance()->getStudentiTest($connection, $codiceTest, $key);



?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Risultati test</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }


            #results {
                padding-top: 3%;

            }

            #resultsCont
            {

            }

            #navigator
            {
                font-size: 14px;
            }

        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=8;
            var currentIndex=0;
            var i=0;

            window.onload = function()
            {

                var results = new GlassBox();
                results.init( 'results', '1040px', '470px', 'auto','',true,false);
                results.ipos();
                results.appear();

            }

            function handler() {
                if(this.readyState == 4 && this.status == 200)
                {

                    location.href="risultatiTest.php?codiceTest=<?= $codiceTest ?>&key=<?= $key ?>";
                    

                } else if (this.readyState == 4 && this.status != 200) {
                    // fetched the wrong page or network error...
                    alert("error this.status : " + this.status );

                }
            }

            function xXMLHttpRequest()
            {

                var client = null;
                if (window.XMLHttpRequest)
                {
                    client=new XMLHttpRequest();
                }
                // code for IE
                else if (window.ActiveXObject)
                {
                    client=new ActiveXObject("Microsoft.XMLHTTP");
                }

                return client;
            }

  function riattivaTestPerStudente(chiave, codiceTest, codiceStudenteToUpdate)
            {
                var client = xXMLHttpRequest();
                client.onreadystatechange = handler;

                var param = "operation=updateStatoStudenteTest"+
                    "&codiceTest="+codiceTest+
                    "&chiaveTest="+chiave+
                    "&codiceStudente="+codiceStudenteToUpdate;
                client.open("POST", "newTestListener.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);

            }


        </script>
    </head>
    <body>

        <?php include '../portal/header.php';?>
        <center>
            <div id="results">
                <div id="resultsCont">
                    <table width="100%" border="1">
                        <tr>
                            <th>Codice</th>
                            <th>Nome</th>
                            <th>Cognome</th>
                            <th>Classe</th>
                            <th>Data esecuzione Test</th>
                            <th>Punteggio</th>
                            <th>Dettaglio</th>
                            <th>Stato</th>
                            <th>Riattiva</th>
                        </tr>
                        <? for($i=0; $i<count($elencoStudenti); $i++)
                        {
                            $statoTest = TestDataManager::getInstance()->getStatoTest($connection, $key, $codiceTest, $elencoStudenti[$i]->getCodiceStudente());
                            $punteggio = TestManager::getInstance()->calcolaPunteggioStudentiTest($connection, $codiceTest, $elencoStudenti[$i]->getCodiceStudente(), $key);
                            $risultati = TestDataManager::getInstance()->getRisposteDate($connection, $elencoStudenti[$i]->getCodiceStudente(), $codiceTest, $key);
                            ?>

                        <tr>
                            <td style="text-align: center"><?= $elencoStudenti[$i]->getCodiceStudente() ?></td>
                            <td><?= $elencoStudenti[$i]->getNome() ?></td>
                            <td><?= $elencoStudenti[$i]->getCognome() ?></td>
                            <td style="text-align: center"><?= $elencoStudenti[$i]->getOrdClasse() ?> <?= $elencoStudenti[$i]->getSezione() ?> <?= $elencoStudenti[$i]->getDescrizioneIndirizzo() ?></td>
                            <td style="text-align: center"><? if(count($risultati) > 0) echo $risultati[0]->getDataRisposta(); else echo '&nbsp;'?></td>
                            <td style="text-align: center"><?= $punteggio ?></td>
                            <td style="text-align: center"><a href="domandeRisultatiTest.php?codiceStudente=<?= $elencoStudenti[$i]->getCodiceStudente() ?>&codiceTest=<?= $codiceTest?>&key=<?= $key ?>"><img src='../images/icons/PNG/Magnifying Glass.png' height='30' width='30' title='Risultati' border='0'/></a></td>
                                <?
                                if($statoTest == "1")
                                {?>
                            <td style="text-align: center">Attivo</td>
                            <td style="text-align: center"><input type="button" value="Riattiva" disabled /> </td>
                                    <?}
                                else
                                {
                                    if($statoTest == "-1")
                                    {
                                        ?>
            
                            <td style="text-align: center">Disattivo</td>
                            <td style="text-align: center"><input type="button" value="Riattiva"
                                                                  onclick="javascript:riattivaTestPerStudente('<?= $key ?>', <?= $codiceTest ?>, <?= $elencoStudenti[$i]->getCodiceStudente()?>)" disabled /></td>
                                            <?
                                        }
                                        else
                                        {
                                            ?>
            
                            <td style="text-align: center">Disattivo</td>
                            <td style="text-align: center"><input type="button" value="Riattiva"
                                                                  onclick="javascript:riattivaTestPerStudente('<?= $key ?>', <?= $codiceTest ?>, <?= $elencoStudenti[$i]->getCodiceStudente()?>)" /></td>
                                            <?}?>
                                        <?}?>
                        </tr>
                            <?}?>
                    </table>

                </div>

            </div>
        </center>
    </body>
</html>
